﻿package tk.mystudio.permission.bean;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

/**
 * 角色类
 * @author jiangkunpeng
 * @since 2011-3-16 
 * @version 1.0
 */
@Entity
@Table(name = "role")
public class Role implements Serializable {

	private static final long serialVersionUID = -5692253433818303604L;

	/**
	 * 角色编号
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id", columnDefinition = "int identity")
	protected Integer id;
	
	/**
	 * 角色名称:要唯一
	 */
	@Column(name = "name", unique = true, columnDefinition = "varchar(20)")
	protected String name;
	
	/**
	 * 角色类型 详见{@link tk.mystudio.permission.constant.RoleType 角色类型常量类}
	 */
	@Column(name = "role_type", columnDefinition = "tinyint")
	protected Integer roleType;
	
	/**
	 * 角色描述
	 */
	@Column(name = "description", columnDefinition = "varchar(60)")
	protected String description;
	
	@ManyToMany(fetch = FetchType.LAZY)  
	@JoinTable(name = "role_resource", inverseJoinColumns = @JoinColumn(name = "resource_id"), joinColumns = @JoinColumn(name = "role_id"))
	protected List<Resource> resources;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public Integer getRoleType() {
		return roleType;
	}
	
	public void setRoleType(Integer roleType) {
		this.roleType = roleType;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	public List<Resource> getResources() {
		return resources;
	}
	
	public void setResources(List<Resource> resources) {
		this.resources = resources;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Role [description=");
		builder.append(description);
		builder.append(", id=");
		builder.append(id);
		builder.append(", name=");
		builder.append(name);
		builder.append(", resources=");
		builder.append(resources);
		builder.append(", roleType=");
		builder.append(roleType);
		builder.append("]");
		return builder.toString();
	}

}
